// src/api/chatAPI.ts

import { request } from "../request";

/**
 * 调用多模态 AI 接口
 * @param messages 聊天消息数组
 * @param responseFormat 可选参数：是否要求返回 json_object 格式
 */
const getChatCompletionAPI = async (
    messages: { role: string; content: string }[],
    responseFormat?: "json_object"
) => {
    const data: any = {
        model: "deepseek-ai/DeepSeek-V3",
        messages,
    };

    // 如果传入了 responseFormat，就添加结构化返回类型
    if (responseFormat === "json_object") {
        data.response_format = { type: "json_object" };
    }

    return request("https://api.siliconflow.cn/v1/chat/completions", {
        method: "post",
        headers: {
            Authorization: "Bearer sk-lghnjmlspvtlhfhnbamhymohfztxbzhmcylqujcgbviiecaz", // 请替换为你的实际 token
            "Content-Type": "application/json",
        },
        data,
    });
};

export default getChatCompletionAPI;
